// KillProcess.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "../WinAPI/WinAPI.h"

int _tmain(int argc, _TCHAR* argv[])
{
	// Local variables
	char strProcess[MAX_PATH], strCmd[MAX_PATH];
//	DWORD dwProcessID;
//	HANDLE hProcess;

	// Function body
	// 1. Specify which process should be launched and terminated
	strcpy_s(strProcess, MAX_PATH*sizeof(char), "Process1.exe");

	// 2. Launch the process
//	CallExe(strProcess, true, NULL);

	// 3. Get ID of the specified process (optional)
	//dwProcessID = FindProcessID(strProcess);
	//printf_s("%s ID = %d\n", strProcess, dwProcessID);
	//fflush(stdout);
	//// Determine if this process ID is valid
	//if (dwProcessID == DWORD(-1))
	//{
	//	printf_s("%s does not exist.\n", strProcess);
	//	fflush(stdout);
	//	return 0;
	//}

	// 4. Terminate the specified process but not along with its descendants (optional)
	//hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
	//TerminateProcess(hProcess, 0);
	//CloseHandle(hProcess);

	// 5. Terminate the specified process along with its descendants using PID (sub-optimal choice)
//	sprintf_s(strCmd, "TASKKILL /PID %d /T /F >NUL 2>&1", dwProcessID);

	// 3. Terminate the specified process along with its descendants using process name (optimal choice)
//	sprintf_s(strCmd, "TASKKILL /PID %d /T /F >NUL 2>&1", strProcess);
	sprintf_s(strCmd, "TASKKILL /IM %s /T /F", strProcess);
	system(strCmd);
}

